package dataAccess;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;



import dataAccess.ReporteXclienteDAO;

import bussinesObjetcs.ReporteXclienteBean;

public class ReporteXclienteDAO {
//	ConnectionDB connectionDB;
	private PreparedStatement consultareporte, insertareporte;
	private Connection connection;
	
	public ReporteXclienteDAO(){
		
	}
	
	public ReporteXclienteDAO(Connection  connection){
      this.connection = connection;
	}

	public Connection getConnection(){
		return connection;
	}
		
	public void setConnection(Connection connection){
	   this.connection = connection;
	}
	
	public ArrayList<ReporteXclienteBean> getOrdenList() {	
		    ArrayList<ReporteXclienteBean> reportexclienteList = new ArrayList<ReporteXclienteBean>();
		    try {
		    	consultareporte = connection.prepareStatement("SELECT * FROM files.reportexcliente");	   
		         // obtain list of colegios
		         synchronized(consultareporte) {
		            ResultSet results = consultareporte.executeQuery();
		            // get rows data{
		            while (results.next()) {
		            	ReporteXclienteBean reportexcliente = new ReporteXclienteBean();
			           
		               reportexcliente.setColegio(results.getString("colegio"));
			           reportexcliente.setCliente(results.getString("cliente"));
			           reportexcliente.setImporte(results.getString("importe"));
			           reportexcliente.setDetalle(results.getString("detalle"));
			           
			           
			           reportexclienteList.add(reportexcliente);
		            }
		        }
		        consultareporte.close();
		    } catch(SQLException sqle){
				 System.out.println(sqle);
			}	   
		    return reportexclienteList;
	   }


	public ReporteXclienteBean searchOrden(String status) {	
		ReporteXclienteBean reportexcliente = null;
		    try {
		         consultareporte = connection.prepareStatement("SELECT * FROM files.reportexcliente WHERE status = cancelada");	   
		         consultareporte.setString(9, status);
		         // obtain ordenes
		         synchronized(consultareporte) {
		            ResultSet results = consultareporte.executeQuery();
		            // get rows data{
			  		  
		            while (results.next()) {	            	
		            	reportexcliente = new ReporteXclienteBean();
			           
		               reportexcliente.setColegio(results.getString("colegio"));
		               reportexcliente.setCliente(results.getString("cliente"));
		               reportexcliente.setImporte(results.getString("importe"));
		               reportexcliente.setDetalle(results.getString("detalle"));
			      
			           
		            }
		        }
		        consultareporte.close();
		    } catch(SQLException sqle){
				 System.out.println(sqle);
			}	   
		    return reportexcliente;
	   }
	 public void addOrden (ReporteXclienteBean reportexcliente)  {
		 try {
		   insertareporte = connection.prepareStatement("INSERT INTO files.reportexcliente VALUES(?,?,?,?,?,?)");
		   synchronized(insertareporte) {
			   
			   
			   insertareporte.setString(1, reportexcliente.getColegio());
			   insertareporte.setString(2, reportexcliente.getCliente());
			   insertareporte.setString(3, reportexcliente.getImporte());
			   insertareporte.setString(4, reportexcliente.getDetalle());
	         
			   insertareporte.executeUpdate();
		   }
		   insertareporte.close();
		 } catch(SQLException sqle){
			 System.out.println(sqle);
		 }
		   
	   }

}